package com.ozo.boot.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ozo.boot.common.base.model.BaseBatchDTO;
import com.ozo.boot.common.base.model.BasePage;
import com.ozo.boot.common.base.model.PageResult;
import com.ozo.boot.common.base.model.ResultVO;
import com.ozo.boot.common.log.annotation.OperateLog;
import com.ozo.boot.system.pojo.dto.ChangeStatusDTO;
import com.ozo.boot.system.pojo.dto.SysDictDataQueryDTO;
import com.ozo.boot.system.pojo.dto.SysDictDataSaveDTO;
import com.ozo.boot.system.entity.SysDictData;
import com.ozo.boot.system.service.ISysDictDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 数据字典 前端控制器
 * </p>
 *
 * @author qiangesoft
 * @since 2024-07-11
 */
@Tag(name = "字典明细管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/dictData")
public class SysDictDataController {

    private final ISysDictDataService sysDictDataService;

    @OperateLog(value = "添加字典项", module = "字典项")
    @SaCheckPermission("system:dictData:add")
    @Operation(summary = "添加字典项")
    @PostMapping("/add")
    public ResultVO<Void> add(@RequestBody @Valid SysDictDataSaveDTO saveDTO) {
        sysDictDataService.add(saveDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "删除字典项", module = "字典项")
    @SaCheckPermission("system:dictData:remove")
    @Operation(summary = "删除字典项")
    @DeleteMapping("/remove")
    public ResultVO<Void> remove(@RequestBody @Valid BaseBatchDTO<Long> batchDTO) {
        sysDictDataService.remove(batchDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "编辑字典项", module = "字典项")
    @SaCheckPermission("system:dictData:edit")
    @Operation(summary = "编辑字典项")
    @PutMapping("/edit")
    public ResultVO<Void> edit(@RequestBody @Valid SysDictDataSaveDTO saveDTO) {
        sysDictDataService.edit(saveDTO);
        return ResultVO.success();
    }

    @SaCheckPermission("system:dictData:page")
    @Schema(description = "字典项分页")
    @GetMapping("/page")
    public ResultVO<PageResult<SysDictData>> page(@Valid BasePage basePage, SysDictDataQueryDTO queryDTO) {
        return ResultVO.success(sysDictDataService.page(basePage, queryDTO));
    }

    @OperateLog(value = "修改状态", module = "字典项")
    @SaCheckPermission("system:dictData:changeStatus")
    @Operation(summary = "修改状态")
    @PutMapping("/changeStatus")
    public ResultVO<Void> changeStatus(@RequestBody @Valid ChangeStatusDTO statusDTO) {
        sysDictDataService.changeStatus(statusDTO);
        return ResultVO.success();
    }

}
